package net.sx.minemodule.widget;

import android.content.Context;
import android.os.Bundle;
import android.support.design.widget.BottomSheetDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.WindowManager;

import net.sx.minemodule.R;
import net.sx.minemodule.adapter.LogisticsSelectAdapter;
import net.sx.minemodule.mvp.bean.LogisticsCompany;

import java.util.List;

/**
 * Created by Administrator 可爱的路人 on 2019/7/6.
 * Email:513421345@qq.com
 * 选择物流公司弹窗
 */
public class LogisticsSelectDialog extends BottomSheetDialog {
    private OnLogisticsSelectCallback onCommitListener;
    private List<LogisticsCompany> data;
    private LogisticsSelectAdapter logisticsSelectAdapter;

    public LogisticsSelectDialog(Context context, List<LogisticsCompany> data, OnLogisticsSelectCallback onCommitListener) {
        super(context);
        this.onCommitListener = onCommitListener;
        this.data = data;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mine_dialog_logistics_select);
        getWindow().getAttributes().width = WindowManager.LayoutParams.MATCH_PARENT;
        getWindow().getAttributes().horizontalMargin = 0;
        findViewById(R.id.mine_iv_logistics_select_close).setOnClickListener(view -> dismiss());
        findViewById(R.id.mine_btn_logistics_select_commit).setOnClickListener(view -> {
            dismiss();
            if (onCommitListener != null) {
                onCommitListener.onCallback(logisticsSelectAdapter.getSelectCompany());
            }
        });
        View btnCommit = findViewById(R.id.mine_btn_logistics_select_commit);
        RecyclerView rvContent = findViewById(R.id.mine_rv_logistics_select_content);
        rvContent.setLayoutManager(new LinearLayoutManager(getContext()));
        logisticsSelectAdapter = new LogisticsSelectAdapter(getContext(), company -> {
            btnCommit.setEnabled(company != null);
        });
        logisticsSelectAdapter.setData(data);
        rvContent.setAdapter(logisticsSelectAdapter);
    }

    public interface OnLogisticsSelectCallback {
        void onCallback(LogisticsCompany logisticsCompany);
    }

}
